import java.awt.BorderLayout;


import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;


public class MainFrameGame extends JFrame{
	
 
 

 private Option gameOption;
 private JFrame parent;
 private MainFrameGame questo = this;
 
	public MainFrameGame(Option gameOp,JFrame par) {
		parent = par ;
		gameOption = gameOp;
		gameOption.setMenu((Menu) parent); 
		gameOption.setMainFrameGame(questo);
		final JFrame frame = new JFrame();
		frame.setTitle("Pong");
		frame.setResizable(false);
		gameOption = gameOp;
		gameOption.setRunning(true);
		gameOption.setGameFrame(frame);
		frame.setSize(par.getSize().width, par.getSize().height);
		
		frame.setResizable(false);
		//   ActionListener All'uscita 
	   //  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				frame.dispose();
				frame.validate();
				gameOption.getMainFrameGame().dispose();
				gameOption.getMainFrameGame().validate();
				gameOption.setRunning(false);
				gameOption.getMenu().setVisible(true);
			}
		});
		   
		BackgroundImgPanel sfondo = new BackgroundImgPanel(gameOption.getBackGroundPath());

		sfondo.setLayout(new BorderLayout());

		GameObjectPanel gioco = new GameObjectPanel(gameOption);
		gameOption.setGameObjectPanel(gioco);
		sfondo.add(gioco, BorderLayout.CENTER);

		frame.add(sfondo);

		frame.setVisible(true);
		
		Thread ballThread = new Thread(gameOption.getNormalBall());
		if(gameOption.getnBalls() == 2 ) {
			Thread otherBallThread = new Thread(gameOption.getOtherBall());
			otherBallThread.start();
		}
		ballThread.start(); // Thread Della palla Start
		Thread p1Thread = new Thread(gameOption.getP1());
	    Thread p2Thread = new Thread(gameOption.getP2());
	    
	    p1Thread.start();
	    p2Thread.start();
		
		


	}
	
	
	
	 
}
